package org.java.user.api.damain;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Objects;

@Entity
@Getter
@Setter
public class Role {
    @Id
    // 使用Hibernate的UUID2算法生成主键的值，适合在分布式环境中使用
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    // 使用前面定义的UUID2算法
    @GeneratedValue(generator = "uuid2")
    @Column(length = 36)
    private String id;
    // 姓名
    private String name;

    // ADMIN、USER、MANAGER等作为身份标识的字符串
    private String roleKey;

    //是否为内置角色
    private boolean builtIn;
    //是否每个用户都具有的固定角色
    private boolean fixed;
//    使用id来保证hashCode的唯一性
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Role)) return false;
        Role role = (Role) o;
        return Objects.equals(id, role.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
